/**
 * Created by Administrator on 2017/6/21 0021.
 */
var F_Lost_Entrance = {
    _init: function () {
        if (B_Login._checkUpdate(), M_HeadFoot._headShow(1), "demo" != M_Init._controller && B_User._isDemoUser()) B_Login._openLogin("background"); else {
            switch (M_Init._clean(), M_Init._controller) {
                case"demo":
                    M_Init._api.innerOperationLostUser = "demoInnerOperationLostUser";
                    break;
                default:
                    M_Init._api.innerOperationLostUser = "innerOperationLostUser"
            }
            M_Init._dateCache.begin = M_Init._dateChoose.begin, M_Init._dateCache.end = M_Init._dateChoose.end, M_Common._getOrderGame("lost", "", "1-2-5"), B_Date._chooseSection({
                autoCommit: !1,
                todayValid: !1
            }, 1, M_Init._dateChoose.begin, M_Init._dateChoose.end, function (a, e) {
                a == M_Init._dateCache.begin && M_Init._dateCache.end == e || (M_Init._dateCache.begin = a, M_Init._dateCache.end = e, F_Lost_Info._getInfo())
            })
        }
    }
}, F_Lost_Info = {
    _init: [{
        type: "togetherTabAvg",
        name: "流失玩家分析",
        tab: ["7日未登录人数", "14日未登录人数", "30日未登录人数"],
        tips: [{}, {
            position: "second",
            content: ["7日未登录的人数：到当日为止，恰为连续7天（含当日）未登录的玩家人数<br>7日未登录的已付费人数：到当日为止，恰为连续7天（含当日）未登录且有付费历史的玩家人数<br>7日未登录的未付费人数：到当日为止，恰为连续7天（含当日）未登录且没有付费历史的玩家人数", "14日未登录的人数：到当日为止，恰为连续14天（含当日）未登录的玩家人数<br>14日未登录的已付费人数：到当日为止，恰为连续14天（含当日）未登录且有付费历史的玩家人数<br>14日未登录的未付费人数：到当日为止，恰为连续14天（含当日）未登录且没有付费历史的玩家人数", "30日未登录的人数：到当日为止，恰为连续30天（含当日）未登录的玩家人数<br>30日未登录的已付费人数：到当日为止，恰为连续30天（含当日）未登录且有付费历史的玩家人数<br>30日未登录的未付费人数：到当日为止，恰为连续30天（含当日）未登录且没有付费历史的玩家人数"]
        }]
    }, {
        type: "switchTab",
        name: "游戏天数分布",
        tab: ["流失玩家", "潜在流失玩家"],
        tips: [{}, {
            position: "second",
            content: ["到当日为止，恰为连续7天（含当日）未登录的玩家在流失前已玩游戏的天数", "之前7日（含当日）有登录记录，且之后7日（不含当日）不再登录的概率大于50%的玩家目前的已玩游戏天数"]
        }]
    }, {
        type: "switchTab",
        name: "等级分布",
        tab: ["流失玩家", "潜在流失玩家"],
        tips: [{}, {
            position: "second",
            content: ["到当日为止，恰为连续7天（含当日）未登录的玩家流失前的等级分布", "之前7日（含当日）有登录记录，且之后7日（不含当日）不再登录的概率大于50%的玩家目前的等级分布"]
        }]
    }, {
        type: "switchTab",
        name: "付费情况",
        tab: ["流失玩家", "潜在流失玩家"],
        tips: [{}, {
            position: "second",
            content: ["到当日为止，恰为连续7天（含当日）未登录的玩家流失前的付费情况", "之前7日（含当日）有登录记录，且之后7日（不含当日）不再登录的概率大于50%的玩家目前的付费情况"]
        }]
    }, {
        type: "regionTab",
        name: "地区分布",
        tab: ["中国地区", "全球地区"],
        tips: [{position: "first", content: "到当日为止，恰为连续7天（含当日）未登录的玩家的地区分布"}]
    }],
    _avg: [[[{label: "AVG：", name: "平均每日7日未登录玩家人数", key: "avg|7d", unit: ""}], [{
        label: "AVG：",
        name: "平均每日14日未登录玩家人数",
        key: "avg|14d",
        unit: ""
    }], [{label: "AVG：", name: "平均每日30日未登录玩家人数", key: "avg|30d", unit: ""}]]],
    _port: [[[{name: "7日未登录的已付费人数", key: "y_axis|7d|paid"}, {
        name: "7日未登录的未付费人数",
        key: "y_axis|7d|unpaid"
    }, {name: "7日未登录的人数", key: "y_axis|7d|total"}], [{
        name: "14日未登录的已付费人数",
        key: "y_axis|14d|paid"
    }, {name: "14日未登录的未付费人数", key: "y_axis|14d|unpaid"}, {
        name: "14日未登录的人数",
        key: "y_axis|14d|total"
    }], [{name: "30日未登录的已付费人数", key: "y_axis|30d|paid"}, {
        name: "30日未登录的未付费人数",
        key: "y_axis|30d|unpaid"
    }, {name: "30日未登录的人数", key: "y_axis|30d|total"}]], [[{
        name: "流失玩家",
        key: "lost_user_oldays|lost"
    }], [{name: "潜在流失玩家", key: "lost_user_oldays|potential_lost"}]], [[{
        name: "流失玩家",
        key: "lost_user_level|lost"
    }], [{name: "潜在流失玩家", key: "lost_user_level|potential_lost"}]], [[{
        name: "流失玩家",
        key: "lost_user_pay|lost"
    }], [{name: "潜在流失玩家", key: "lost_user_pay|potential_lost"}]], [[{
        name: "国内地区分布",
        key: "lost_user_area|china"
    }], [{name: "国际地区分布", key: "lost_user_area|global"}]]],
    _domInit: function () {
        M_Inside._htmlChartTable($("#ct_main_area"), F_Lost_Info._init), M_Inside._downloadCsv(), F_Lost_Info._getInfo()
    },
    _getInfo: function () {
        for (var a = M_Init._dateCache.begin, e = M_Init._dateCache.end, t = [], _ = 0; _ < F_Lost_Info._init.length; _++)t.push("bs_chart_" + _ + "_0");
        var n = {};
        n.start_date = a, n.end_date = e, n.game_id = M_Init._gameId, n = B_Common._postData(n), B_Port._ajax(M_Init._api.innerOperationLostUser, "post", !0, n, function () {
            for (var a = 0; a < t.length; a++)$("#" + t[a]).html(B_Pre._loading())
        }, function () {
            for (var a = 0; a < t.length; a++)$("#" + t[a]).html("")
        }, function (a, e) {
            if (a) {
                M_Init._dataCache.data = a;
                for (var t = 0; t < F_Lost_Info._init.length; t++)if (F_Lost_Info._init[t].tab.length > 0) {
                    M_Init._dataCache["position_" + t] || (M_Init._dataCache["position_" + t] = 0);
                    for (var _ = 0; _ < F_Lost_Info._init[t].tab.length; _++)if (M_Init._dataCache["position_" + t] == _) {
                        F_Lost_Info._chartHtml(t, _), M_Inside._chartTableIcon(F_Lost_Info._init[t].type, t, _);
                        break
                    }
                    M_Inside._tabChangePerChart(t, F_Lost_Info._init[t].type, "lost")
                } else F_Lost_Info._chartHtml(t, 0), M_Inside._chartTableIcon(F_Lost_Info._init[t].type, t, 0)
            }
        }, function (a, e, _) {
            for (var n = 0; n < t.length; n++)$("#" + t[n]).html(B_Pre._empty(e))
        })
    },
    _chartHtml: function (a, e, t) {
        M_Init._dataCache["position_" + a] = e;
        var _ = M_Init._dataCache.data, n = {x_axis: [], y_axis: [], yFormat: ""}, o = {}, s = 50, i = "";
        switch (a + "") {
            case"0":
                n.xFormatDate = !0, n.xFormatDate = !0, n.yFormat = "", n.tooltip = {num: 3, unit: "人"}, i = "人";
                break;
            case"1":
            case"2":
            case"3":
            case"4":
                n.tooltip = {num: 1, unit: "人"}
        }
        switch (a + "") {
            case"1":
                o = {head: ["已玩天数", F_Lost_Info._port[a][e][0].name + "(人)", "玩家占比"], body: []};
                break;
            case"2":
                o = {head: ["玩家等级分布", F_Lost_Info._port[a][e][0].name + "(人)", "玩家占比"], body: []};
                break;
            case"3":
                o = {head: ["付费情况", F_Lost_Info._port[a][e][0].name + "(人)", "玩家占比"], body: []};
                break;
            case"4":
                o = {head: ["地区", F_Lost_Info._port[a][e][0].name + "(人)", "玩家占比"], body: []};
                break;
            default:
                o = {head: ["日期"], body: []}
        }
        for (var r = 0; r < F_Lost_Info._port[a][e].length; r++) {
            var d = F_Lost_Info._port[a][e][r].key.split("|"), l = F_Lost_Info._port[a][e][r].name;
            if (1 == a) {
                if (s = 20, _[d[0]][d[1]]) {
                    for (var y = _[d[0]][d[1]], p = [], h = 0; h < y.length; h++)y[h].oldays_classify = y[h].oldays_classify.replace("&gt;", ">"), y[h].oldays_classify = y[h].oldays_classify.replace("&lt;", "<"), n.x_axis.push(y[h].oldays_classify), p.push(y[h].user_num), o.body[h] || (o.body[h] = [y[h].oldays_classify]), o.body[h].push(y[h].user_num), o.body[h].push(y[h].user_rate + "%");
                    n.y_axis.push({name: l, data: p})
                }
            } else if (2 == a) {
                if (s = 40, _[d[0]][d[1]]) {
                    for (var y = _[d[0]][d[1]], p = [], h = 0; h < y.length; h++)n.x_axis.push(y[h].level + "级"), p.push(y[h].user_num), o.body[h] || (o.body[h] = [y[h].level + "级"]), o.body[h].push(y[h].user_num), o.body[h].push(y[h].user_rate + "%");
                    n.y_axis.push({name: l, data: p})
                }
            } else if (3 == a) {
                if (s = 20, _[d[0]][d[1]]) {
                    for (var y = _[d[0]][d[1]], p = [], h = 0; h < y.length; h++)y[h].pay_amount_classify = y[h].pay_amount_classify.replace("&gt;", ">"), y[h].pay_amount_classify = y[h].pay_amount_classify.replace("&lt;", "<"), n.x_axis.push(y[h].pay_amount_classify), p.push(y[h].user_num), o.body[h] || (o.body[h] = [y[h].pay_amount_classify]), o.body[h].push(y[h].user_num), o.body[h].push(y[h].user_rate + "%");
                    n.y_axis.push({name: l, data: p})
                }
            } else if (4 == a) {
                if (s = 20, _[d[0]][d[1]]) {
                    for (var y = _[d[0]][d[1]], p = [], h = 0; h < y.length; h++)n.x_axis.push(y[h].area_classify), p.push(y[h].user_num), o.body[h] || (o.body[h] = [y[h].area_classify]), o.body[h].push(y[h].user_num), o.body[h].push(y[h].user_rate + "%");
                    n.y_axis.push({name: l, data: p})
                }
            } else if (s = 50, n.x_axis = _.x_axis, "%" != i ? o.head.push(l + "(" + i + ")") : o.head.push(l), _[d[0]] && _[d[0]][d[1]] && _[d[0]][d[1]][d[2]]) {
                for (var y = _[d[0]][d[1]][d[2]], h = 0; h < y.length; h++)o.body[h] || (o.body[h] = [_.x_axis[h]]), "%" != i ? o.body[h].push(y[h]) : o.body[h].push(y[h] + i);
                n.y_axis.push({name: l, data: y})
            }
        }
        if (F_Lost_Info._avg[a] && F_Lost_Info._avg[a][e]) {
            for (var c = "", u = F_Lost_Info._avg[a][e], m = 0; m < u.length; m++)u[m].label && (c += "<span>" + u[m].label + "</span>"), c += "<span>" + u[m].name + "<b>", d = u[m].key.split("|"), _[d[0]] && _[d[0]][d[1]] && (c += _[d[0]][d[1]]), c += u[m].unit + "</b></span>";
            M_Inside._avgHtml(a + "_0", c)
        }
        o.name = M_Inside._tableName(F_Lost_Info._init, a, e, M_Init._dateCache.begin, M_Init._dateCache.end), e = 0, M_Init._dataCache[a + "_" + e] = o, M_Inside_Chart._chartData(s, "bs_chart_" + a + "_" + e, n), M_Inside._tableHtml(1, a + "_" + e)
    }
};